package com.gustuy.learn1;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;

public class UdpClient {
    //建立socket
    public static void main(String[] args) throws Exception {
        //1.建立socket
        DatagramSocket socket=new DatagramSocket();
        //2.建包
        String msg="你好!";
        InetAddress local=InetAddress.getLocalHost();
        int port=9999;
        DatagramPacket packet= new DatagramPacket(msg.getBytes(),0,msg.getBytes().length,local,port);
        socket.send(packet);
        socket.close();
    }
}
